<?
require_once("cms/core/helper/bean/Abstract.php");
require_once("cms/gallery/om/GalleryPeer.php");
require_once("cms/gallery/om/GalleryImagePeer.php");

class PHP_CMS_View_Helper_Galleries extends AbstractList {

    public function galleries($form=null) {

        if($this->isInit)
            return $this;

        parent::init($form);

        $this->criteria->addJoin(
            GalleryPeer::GALLERY_ID, GalleryImagePeer::GALLERY_ID, Criteria::LEFT_JOIN);

        $this->criteria->addAsColumn(
            'imageCount', 'COUNT(' . GalleryImagePeer::GALLERY_IMAGE_ID . ')');

        $this->criteria->addGroupByColumn(
            GalleryImagePeer::GALLERY_ID);

        $this->criteria->setDistinct();

        return $this;

    }


    /**
     * Define the propel peer we are going to use to list
     * page items.
     */
    public static function getPeer() {
        return new GalleryPeer();
    }


    /**
     * Return the searchable fields for this list page.
     */
    public static function getFields() {
        return array(
            GalleryPeer::NAME,
            GalleryPeer::INSERT_DATE,
            GalleryPeer::MODIFIED_DATE
        );
    }
}
?>